module.exports = function mountLoopBackExplorer(app) {
  let explorer;
  try {
    explorer = require('loopback-component-explorer');
  } catch (err) {
    // Print the message only when the app was started via `app.listen()`.
    // Do not print any message when the project is used as a component.
    app.once('started', function (baseUrl) {
      console.error('Run `npm install loopback-component-explorer` to enable the LoopBack explorer');
    });
    return;
  }
  // 用户名 test 密码 123456
  app.use('/explorer', require('node-basicauth')({ test: '123456' }));

  app.use('/explorer', explorer.routes(app, { basePath: app.get('restApiRoot') }));

  app.once('started', function () {
    let baseUrl = app.get('url').replace(/\/$/, '');
    console.log('通过了验证信息，查看REST API %s%s', baseUrl, '/explorer');
  });
};
